import { http } from "@/utils/http";

/** 分布式数据表模型定义 */
export type DistributeTableModel = {
  id: number;
  timeBy: number;
  time: string;
  serverKey: string;
  table: string;
  flag: string;
  createdAt: string;
  updatedAt: string;
  status: number;
  isExpire: number;
  duration: number;
  totalAmount: number;
  totalSize: number;
};

/** 分页获取分发表列表 */
export const getDistributeTableListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<DistributeTableModel>>>(
    "get",
    "/clusters/distribute-tables/page-list",
    { params: data }
  );
};

/** 删除分发表 */
export const deleteDistributeTableApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/clusters/distribute-tables/${id}`);
};

/** 根据ID获取分发表详情 */
export const getDistributeTableByIdApi = (id: number) => {
  return http.request<Resp<{
    info: DistributeTableModel
  }>>('get', `/clusters/distribute-tables/${id}`);
};

/** 更新分发表 */
export const updateDistributeTableApi = (id: number, data: Partial<DistributeTableModel>) => {
  return http.request<Resp<null>>(
    "put",
    `/clusters/distribute-tables/${id}`,
    { data }
  );
};

/** 获取分发表选项 */
export const getDistributeTableOptionsApi = (deptId:number, fieldKey: string, fieldLabel: string) => {
  return http.request<Resp<{
    options: Array<{
      val: any;
      label: string;
    }>
  }>>("get", "/clusters/distribute-tables/options", {
    params: { deptId,fieldKey, fieldLabel }
  });
};
